// /rule/addRuleInfo.do
document
		.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document
		.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '../table/addTablesInfo.do';
var _url_edit = '../table/updateTablesInfo.do';
var _url_list = '../table/getTablesList';
var _url_id = '../table/getTablesById';
var _map = {};
// /首页
var _pageNum = 1;
var _type;
var spid = "";
$(function() {

	spid = getCookie("shop_id");
	_type = getUrlParam("type");
	console.log(_type);
	if (_type === "add") {
		// getTypeListAdd();
		_showData = {};
		$("#shopId").val(spid);
	} else if (_type === "edit") {
		showEditData();
		_url_ = _url_edit;
	} else {
		// getTypeList();
		// getProfitsInfo();
		getList();
	}
})
$(function() {
	$("body").on("click", ".mypage span", function() {
		_pageNum = $(this).attr("data-status");
		getList();
	})
	$(".search-btn").click(function() {
		var tabletitle = $("#table-title").val();
		_map["title"] = tabletitle;
		_pageNum = 1;
		getList();
	});
	$("body").on(
			"click",
			".left-type li",
			function() {
				var tt = $(this).text();
				$(this).addClass('lt-li-active').siblings().removeClass(
						'lt-li-active');
				_map['goodsTypeId'] = $(this).attr('data-status');
				getList();
			});
});
function getList() {
	_map['shopId'] = spid;
	_map['pageNum'] = _pageNum;
	_ajax_get(
			_url_list,
			_map,
			function(res) {
				console.log(res);
				console.log(res.returnObject);
				if (!res.returnObject || res.returnObject.length <= 0) {
					$(".layui-table tbody").html("");
					$(".no-more-data").show();
					$(".mypage").hide();
					return;
				} else {
					$(".mypage").show();
					$(".no-more-data").hide();
				}
				var html = "";
				var stat = "", statHtml = "";
				showPageInfo(res.returnObject);
				$(".x-right").text("共有数据：" + res.returnObject.total + " 条");
				var html, stat, statStr, payTypeStr, sendTypeStr;
				$
						.each(
								res.returnObject.list,
								function(i, v, arr) {
									console.log(v);
									if (v.orderNum >= 1) {
										statStr = ' <a href="javascript:;" onclick="parent.clickMenuOnChildParam(\'order~order-list.html?orderType=2\');setCookie(\'dangqianOrder\',\''+v.id+'\')" class="showDetail " >查看当前订单</a>';
									} else {
										statStr = ' <a href="javascript:;"  class="showDetail dis" >查看当前订单</a>';
									}
									html += ' <tr><td>'
											+ ' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'
											+ v.id
											+ '" ><i class="layui-icon">&#xe605;</i></div>'
											+ ' </td>                                                                                                                  '
											+ ' <td>'
											+ v.sort
											+ '</td>                                                                                                             '
											+ ' <td>'
											+ v.title
											+ '</td>                                                                                           '
											// +' <td align="center"><a
											// target="_blank"
											// href="'+v.adUrl+'"><img
											// src="'+v.adPic+'" height=50
											// widht=50 ></a></td> '
											// +' <td>'+v.adUrl+'</td> '
											+ ' <td>'
											+ v.num
											+ '</td>                                                                                                      '
											+ ' <td >'
											+ v.orderNum
											+ '</td>'
											+ ' <td class="qrcord-td"><span onclick="showQr(\''
											+ v.title
											+ '\',\''
											+ v.qrcodePic
											+ '\');">查看</span><span onclick="downQr(\''
											+ v.id
											+ '\')">下载</span></td>                                                                                                      '
											+ ' <td class="td-manage">    '
											+ statStr
											+ '   <a title="编辑"  onclick="x_admin_show(\'修改桌台 - '
											+ v.title
											+ '\',\'./table~shop-table-add.html?type=edit&id='
											+ v.id
											+ '\',451,330)" href="javascript:;">                       '
											+ '     <i class="iconfont">修改</i>                                                                                 '
											+ '   </a>'
											// + '<a title="删除"
											// onclick="member_del(this,\''+v.id+'\')"
											// href="javascript:;"> '
											// +' <i class="iconfont icon-delete
											// x-red"></i> </a> '
											+ '     </td> </tr>';
								})
				$(".layui-table tbody").html(html);
			})
}

/* 用户-删除 */
function member_del(obj, _id) {
	layer.confirm('确认要删除吗？', function(index) {
		// 发异步删除数据
		_ajax_post_token(_url_edit, {
			status : 0,
			id : _id
		}, function(res) {
			console.log(res);
			if (res.resultCode == 1000) {
				getList();
				layer.msg('删除成功!', {
					icon : 6,
					time : 2000
				});
			} else {
				layer.msg('删除失败!', {
					icon : 5,
					time : 2000
				});
			}
		});
	});
}
function showQr(_title, _url) {
	layer.open({
		title : _title,
		content : '<img width=250 height=250 src="' + _url + '" />'
	});
}
function downQrBatch(argument) {
	var data = tableCheck.getData();
	if (!data || data.length == 0) {
		layer.msg('至少选择一条数据', {
			icon : 5,
			time : 2000
		});
		return;
	}
	console.log(data.join(","));
	window.location.href = '../table/downQrBatch?ids=' + data.join(",");
	// _ajax_get('../table/downQrBatch',{ids:data.join(",")},function(res){
	// console.log(res);
	// });
}
function downQr(_id) {
	window.location.href = '../table/downQr?id=' + _id;
}
function showEditData() {
	_url_ = _url_edit;
	var _id = getUrlParam("id");
	$("#paramKey").val(_id);
	console.log(_id);
	_ajax_post_token(_url_id, {
		id : _id
	}, function(res) {
		console.log(res);
		_showData = res.returnObject;
	});
}
function updateInfo(data) {
	// 发异步，把数据提交给后台
	console.log(_url_);
	disAddBtn();
	data['shopId'] = spid;
	_ajax_post_token(_url_, data, function(res) {
		console.log(res);
		if (res.resultCode == 1000) {
			parent.getList();
			parent.layer.msg('操作成功!', {
				icon : 6,
				time : 2000
			});
			x_admin_close();
			// 获得frame索引
		} else {
			layer.msg('操作失败!', {
				icon : 5,
				time : 2000
			});
		}
		celDisAddBtn();
	});
}

function delAll(argument) {
	var data = tableCheck.getData();
	if (!data || data.length == 0) {
		layer.msg('至少选择一条数据', {
			icon : 5,
			time : 2000
		});
		return;
	}
	console.log(data.join(","));
	layer.confirm('确认要删除已选择的数据吗？', function(index) {
		// 捉到所有被选中的，发异步进行删除
		_ajax_post_token(_url_edit, {
			ids : data.join(",")
		}, function(res) {
			console.log(res);
			if (res.resultCode == 1000) {
				getList();
				layer.msg('操作成功!', {
					icon : 6,
					time : 2000
				});
				// 获得frame索引
			} else {
				layer.msg('操作失败!', {
					icon : 5,
					time : 2000
				});
			}
		});
	});
}

function test(_d) {
	console.log(_d);
}

// 添加 和 修改窗口
